import { RoutesAlias } from '../routesAlias'
import { AppRouteRecord } from '@/types/router'
import { WEB_LINKS } from '@/utils/constants'

/**
 * 菜单列表、异步路由
 *
 * 支持两种模式:
 * 1. 前端静态配置 - 直接使用本文件中定义的路由配置
 * 2. 后端动态配置 - 后端返回菜单数据，前端解析生成路由
 *
 * 菜单标题（title）:
 * 可以是 i18n 的 key，也可以是字符串，比如：'用户列表'
 */
export const asyncRoutes: AppRouteRecord[] = [
  {
    name: 'Dashboard',
    path: '/dashboard',
    component: RoutesAlias.Home,
    meta: {
      title: 'menus.dashboard.title',
      icon: '&#xe721;'
    },
    children: [
      {
        path: 'console',
        name: 'Console',
        component: RoutesAlias.Dashboard,
        meta: {
          title: 'menus.dashboard.console',
          keepAlive: false,
          fixedTab: true
        }
      },
      {
        path: 'analysis',
        name: 'Analysis',
        component: RoutesAlias.Analysis,
        meta: {
          title: 'menus.dashboard.analysis',
          keepAlive: false
        }
      },
      {
        path: 'ecommerce',
        name: 'Ecommerce',
        component: RoutesAlias.Ecommerce,
        meta: {
          title: 'menus.dashboard.ecommerce',
          keepAlive: false
        }
      }
    ]
  },
  {
    path: '/system',
    name: 'System',
    component: RoutesAlias.Home,
    meta: {
      title: 'menus.system.title',
      icon: '&#xe7b9;',
      roles: ['R_SUPER', 'R_ADMIN']
    },
    children: [
		{
		  path: 'org',
		  name: 'Org',
		  component: RoutesAlias.Org,
		  meta: {
		    title: 'menus.system.org',
		    keepAlive: true,
		    roles: ['R_SUPER'],
		    authList: [
		      {
		        title: '新增',
		        auth_mark: 'add'
		      },
		      {
		        title: '编辑',
		        auth_mark: 'edit'
		      },
		      {
		        title: '删除',
		        auth_mark: 'delete'
		      }
		    ]
		  }
		},
      {
        path: 'user',
        name: 'User',
        component: RoutesAlias.User,
        meta: {
          title: 'menus.system.user',
          keepAlive: true,
          roles: ['R_SUPER', 'R_ADMIN']
        }
      },
      {
        path: 'role',
        name: 'Role',
        component: RoutesAlias.Role,
        meta: {
          title: 'menus.system.role',
          keepAlive: true,
          roles: ['R_SUPER']
        }
      },
      {
        path: 'user-center',
        name: 'UserCenter',
        component: RoutesAlias.UserCenter,
        meta: {
          title: 'menus.system.userCenter',
          isHide: true,
          keepAlive: true,
          isHideTab: true
        }
      },
      {
        path: 'menu',
        name: 'Menus',
        component: RoutesAlias.Menu,
        meta: {
          title: 'menus.system.menu',
          keepAlive: true,
          roles: ['R_SUPER'],
          authList: [
            {
              title: '新增',
              auth_mark: 'add'
            },
            {
              title: '编辑',
              auth_mark: 'edit'
            },
            {
              title: '删除',
              auth_mark: 'delete'
            }
          ]
        }
      },
      {
        path: 'dict',
        name: 'Dict',
        component: RoutesAlias.Dict,
        meta: {
          title: 'menus.system.dict',
          keepAlive: true,
          roles: ['R_SUPER'],
          authList: [
            {
              title: '新增',
              auth_mark: 'add'
            },
            {
              title: '编辑',
              auth_mark: 'edit'
            },
            {
              title: '删除',
              auth_mark: 'delete'
            }
          ]
        }
      }
    ]
  },
  {
    path: '/settings',
    name: 'Settings',
    component:RoutesAlias.Home,
    meta: {
      title: 'menus.settings.title',
      icon: '&#xe77c;',
      roles: ['R_SUPER', 'R_ADMIN']
    },
    children: [
      {
        path: 'dataSource',
        name: 'DataSource',
        component:RoutesAlias.SettingDataSource,
        meta: {
          title: 'menus.settings.dataSource',
          keepAlive: true,
          roles: ['R_SUPER', 'R_ADMIN']
        }
      },
      {
        path: 'meta',
        name: 'Meta',
        component: RoutesAlias.SettingMeta,
        meta: {
          title: 'menus.settings.meta',
          keepAlive: true,
          roles: ['R_SUPER']
        }
      },
    ]
  },
  {
    path: '/log',
    name: 'Log',
    component: RoutesAlias.Home,
    meta: {
      title: 'menus.log.title',
      icon: '&#xe816;',
      keepAlive: false
    },
    children: [
      {
        path: 'login',
        name: 'LoginLog',
        component: RoutesAlias.LoginLog,
        meta: {
          title: 'menus.log.login',
          keepAlive: true
        }
      },
	  {
	    path: 'operate',
	    name: 'OperateLog',
	    component: RoutesAlias.OperateLog,
	    meta: {
	      title: 'menus.log.operate',
	      keepAlive: true
	    }
	  },
	  {
	    path: 'run',
	    name: 'RunLog',
	    component: RoutesAlias.RunLog,
	    meta: {
	      title: 'menus.log.run',
	      keepAlive: true
	    }
	  }
    ]
  },
  {
    name: 'Help',
    path: '/help',
    component: RoutesAlias.Home,
    meta: {
      title: 'menus.help.title',
      icon: '&#xe719;',
      keepAlive: false,
      roles: ['R_SUPER', 'R_ADMIN']
    },
    children: [
      {
        path: '',
        name: 'Document',
        meta: {
          title: 'menus.help.document',
          link: WEB_LINKS.DOCS,
          isIframe: false,
          keepAlive: false
        }
      }
    ]
  },
  // 一级菜单
  {
    name: 'ChangeLog',
    path: '/change/log',
    component: RoutesAlias.ChangeLog,
    meta: {
      title: 'menus.plan.log',
      showTextBadge: `v${__APP_VERSION__}`,
      icon: '&#xe712;',
      keepAlive: false
    }
  },
  // 可视化应用
  {
    path: '/visual-app',
    name: 'VisualApp',
    component: RoutesAlias.Home,
    meta: {
      title: '可视化应用',
      cnTitle: '可视化应用',
      enTitle: 'Visual Application',
      icon: '&#xe7b9;',
      keepAlive: false
    },
    children: [
      {
        path: 'project/edit',
        name: 'VisualAppProjectEdit',
        component: RoutesAlias.VisualAppProjectEdit,
        meta: {
          title: '项目编辑',
          cnTitle: '项目编辑',
          enTitle: 'Project Edit',
          keepAlive: false
        }
      },
      {
        path: 'project/preview',
        name: 'VisualAppProjectPreview',
        component: RoutesAlias.VisualAppProjectPreview,
        meta: {
          title: '项目预览',
          cnTitle: '项目预览',
          enTitle: 'Project Preview',
          keepAlive: false,
          isHide: true // 隐藏菜单，只用于预览
        }
      }
    ]
  }
]
